<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册 - 招聘系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <style>
        body {
            background: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
        }
        .register-container {
            max-width: 500px;
            margin: 0 auto;
            padding: 20px;
        }
        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            backdrop-filter: blur(10px);
            background: rgba(255, 255, 255, 0.9);
        }
        .card-header {
            background: transparent;
            border-bottom: none;
            text-align: center;
            padding: 30px 20px 20px;
        }
        .card-header h4 {
            color: #2c3e50;
            font-weight: 600;
        }
        .card-body {
            padding: 30px;
        }
        .form-control {
            border-radius: 8px;
            padding: 12px 15px;
            border: 1px solid #e0e0e0;
            background: rgba(255, 255, 255, 0.9);
            transition: all 0.3s ease;
        }
        .form-control:focus {
            box-shadow: 0 0 0 3px rgba(161, 196, 253, 0.3);
            border-color: #a1c4fd;
        }
        .btn-primary {
            padding: 12px;
            border-radius: 8px;
            background: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%);
            border: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(161, 196, 253, 0.4);
        }
        .alert {
            display: none;
            margin-bottom: 20px;
            border-radius: 8px;
        }
        .form-label {
            color: #2c3e50;
            font-weight: 500;
            margin-bottom: 8px;
        }
        .login-link {
            color: #2c3e50;
            text-decoration: none;
            transition: all 0.3s ease;
        }
        .login-link:hover {
            color: #a1c4fd;
        }
        .input-group-text {
            background: transparent;
            border: 1px solid #e0e0e0;
            border-right: none;
        }
        .input-group .form-control {
            border-left: none;
        }
        .input-group .form-control:focus {
            border-left: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="register-container">
            <div class="card">
                <div class="card-header">
                    <h4><i class="bi bi-person-plus me-2"></i>用户注册</h4>
                </div>
                <div class="card-body">
                    <div class="alert alert-danger" id="errorAlert" role="alert"></div>
                    
                    <form id="registerForm" onsubmit="return handleRegister(event)">
                        <div class="mb-4">
                            <label for="username" class="form-label">用户名</label>
                            <div class="input-group">
                                <span class="input-group-text">
                                    <i class="bi bi-person"></i>
                                </span>
                                <input type="text" class="form-control" id="username" name="username" required>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <label for="password" class="form-label">密码</label>
                            <div class="input-group">
                                <span class="input-group-text">
                                    <i class="bi bi-lock"></i>
                                </span>
                                <input type="password" class="form-control" id="password" name="password" required>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <label for="confirmPassword" class="form-label">确认密码</label>
                            <div class="input-group">
                                <span class="input-group-text">
                                    <i class="bi bi-lock-fill"></i>
                                </span>
                                <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" required>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <label for="realName" class="form-label">真实姓名</label>
                            <div class="input-group">
                                <span class="input-group-text">
                                    <i class="bi bi-person-badge"></i>
                                </span>
                                <input type="text" class="form-control" id="realName" name="realName" required>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <label for="phone" class="form-label">手机号码</label>
                            <div class="input-group">
                                <span class="input-group-text">
                                    <i class="bi bi-phone"></i>
                                </span>
                                <input type="tel" class="form-control" id="phone" name="phone" required>
                            </div>
                        </div>
                        
                        <div class="mb-4">
                            <label for="email" class="form-label">电子邮箱</label>
                            <div class="input-group">
                                <span class="input-group-text">
                                    <i class="bi bi-envelope"></i>
                                </span>
                                <input type="email" class="form-control" id="email" name="email" required>
                            </div>
                        </div>
                        
                        <div class="d-grid gap-2 mb-4">
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-person-plus me-2"></i>注册
                            </button>
                        </div>
                        
                        <div class="text-center">
                            <a href="/login" class="login-link">
                                <i class="bi bi-arrow-left me-1"></i>返回登录
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        function handleRegister(event) {
            event.preventDefault();
            
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const confirmPassword = document.getElementById('confirmPassword').value;
            const realName = document.getElementById('realName').value;
            const phone = document.getElementById('phone').value;
            const email = document.getElementById('email').value;
            const errorAlert = document.getElementById('errorAlert');
            
            // 验证密码
            if (password !== confirmPassword) {
                errorAlert.style.display = 'block';
                errorAlert.textContent = '两次输入的密码不一致';
                return false;
            }
            
            // 创建FormData对象
            const formData = new FormData();
            formData.append('username', username);
            formData.append('password', password);
            formData.append('realName', realName);
            formData.append('phone', phone);
            formData.append('email', email);
            formData.append('role', 'USER'); // 默认角色
            
            axios.post('/register', formData)
            .then(response => {
                if (response.data === 'success') {
                    alert('注册成功，请登录');
                    window.location.href = '/login';
                } else {
                    errorAlert.style.display = 'block';
                    errorAlert.textContent = response.data;
                }
            })
            .catch(error => {
                errorAlert.style.display = 'block';
                errorAlert.textContent = '注册失败：' + (error.response?.data || '未知错误');
            });
            
            return false;
        }
    </script>
</body>
</html> 